<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="recordList">
      <el-table-column label="序号" align="center" prop="id"/>
      <el-table-column label="图书序号" align="center" prop="bookId"/>
      <el-table-column label="借阅时间" align="center" prop="borrowTime"/>
      <el-table-column label="应归还时间" align="center" prop="returnTime" />
      <el-table-column label="是否逾期" align="center" prop="overdue" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.lib_book_overdue" :value="scope.row.overdue"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleQueryById(scope.row)"
          >详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 详情框 -->
    <el-dialog title="借阅详情" :visible.sync="open" width="780px" append-to-body>
      <el-form ref="form" :model="form" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="序号" prop="id">
              <el-input v-model="form.id" :disabled="true"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用户" prop="userName">
              <el-input v-model="form.userName" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="图书序号" prop="bookId">
              <el-input v-model="form.bookId" :disabled="true"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="图书名" prop="bookTitle">
              <el-input v-model="form.bookTitle" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="借阅时间" prop="borrowTime">
              <el-input v-model="form.borrowTime" :disabled="true"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="归还状态" prop="status">
              <el-select v-model="form.status" placeholder="归还状态" clearable :disabled="true">
                <el-option
                  v-for="dict in dict.type.lib_book_return"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="应归还时间" prop="returnTime">
              <el-input v-model="form.returnTime" :disabled="true"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="实际归还时间" prop="actualReturnTime">
              <el-input v-model="form.actualReturnTime" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="逾期状态" prop="overdue">
              <el-select v-model="form.overdue" placeholder="逾期状态" clearable :disabled="true">
                <el-option
                  v-for="dict in dict.type.lib_book_overdue"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listRecord} from '@/api/borrow/mybook'
import {getRecord} from '@/api/borrow/borrowRecord'

export default {
  name: 'Book',
  dicts: ['lib_book_return', 'lib_book_overdue'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 图书表格数据
      recordList: [],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: undefined,
        status: undefined
      },
      categoryOptions: [],
      // 表单参数
      form: {},
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询图书列表 */
    getList() {
      this.loading = true
      listRecord(this.queryParams).then(response => {
        this.recordList = response.data
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        userName: undefined,
        bookTitle: undefined,
        bookId: undefined,
        borrowTime: undefined,
        returnTime: undefined,
        actualReturnTime: undefined,
        overdue: '0',
        status: '0'
      }
      this.resetForm('form')
    },
    handleQueryById(row) {
      this.reset()
      const id = row.id
      getRecord(id).then(response => {
        this.form = response.data
        this.open = true
      })
    },
  }
}
</script>
